package com.cskaoyan.controller;

import com.cskaoyan.annotation.LogRecord;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.GenericData;
import com.cskaoyan.bean.admin.AdminBo;
import com.cskaoyan.bean.admin.AdminCreateVo;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.po.MarketAdmin;
import com.cskaoyan.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiangRuiJiang
 * @since 2022/06/05  23:20
 */
@RestController
@RequestMapping("admin/admin")
public class AdminController {

    @Autowired
    AdminService adminService;

    /**
     * 查询管理人员列表
     * @param baseParam
     * @param username
     * @return
     */
    @LogRecord
    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam,String username){

        GenericData adminList = adminService.queryAdminList(baseParam,username);
        return BaseRespVo.ok(adminList);
    }

    /**
     * 创建管理员信息
     * @param admin
     * @return
     */
    @LogRecord
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody() MarketAdmin admin){

        AdminCreateVo marketAdmin = adminService.createAdmin(admin);
        return BaseRespVo.ok(marketAdmin);
    }

    /**
     * 编辑管理员信息
     * @param admin
     * @return
     */
    @LogRecord
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody() MarketAdmin admin){

        AdminCreateVo adminVo = adminService.updateAdmin(admin);
        return BaseRespVo.ok(adminVo);
    }

    /**
     * 逻辑删除管理员信息
     * @param admin
     * @return
     */
    @LogRecord
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody() MarketAdmin admin){
        adminService.deleteAdmin(admin);
        return BaseRespVo.ok();
    }
}
